package cn.tedu.sentinel01;

import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.ArrayList;
import java.util.List;

@SpringBootApplication
public class Sentinel01Application {

    public static void main(String[] args) {

        SpringApplication.run(Sentinel01Application.class, args);
//        在main方法内部
        List<FlowRule> flowRules = new ArrayList<>();
        FlowRule flowRule = new FlowRule();
        flowRule.setResource("sayHi");
//        1 qps 一台服务器在一秒内能处理的请求量
//        0 并发 当前系统在一秒内能处理的请求量
        flowRule.setGrade(1);
//        设置上限
        flowRule.setCount(1);
        flowRules.add(flowRule);
        //sentinel组件，加载定义的规则
        FlowRuleManager.loadRules(flowRules);
        //目前规则定义的意思是：访问sayHi  qps超过阈值1  就会限流，不让访问
    }

}
